require.config({
	baseUrl : "/jinandi",
	paths : {
		"jquery" : "js/jquery.min"
	}
});

require(["jquery"], function($) {
	  $(function() {
	      $("#validateCode").click(function() {
	    	$("#validateCode").attr("src","../login/validateCode/images?"+Math.random());
	      });
	  $("#loginForm").submit( function() {
		 	if($.trim($("#username").val())==''){
	   			alert('用户名不能为空');
	   			$("#username")[0].focus();
	   			return false;
	   		}else if($.trim($("#password").val())==""){
	   			alert('密码不能为空');
	   			$("#password")[0].focus();
	   			return false;
	   		}else if($("#valcode").val().length<4){
	   			alert('验证码必须为四位');
	   			$("#valcode")[0].focus();
	   			return false;
	   		}else{
	   		  $.ajax({
				  type: 'POST',
				  url: '../j_spring_security_check',
				  data: $( '#loginForm' ).serialize(),
				  success: function(data, textStatus, jqXHR){
				  		if(data=="-图形校验码输入出错！"){
		   			 	alert('验证码错误');
		   			 	$("#valcode")[0].focus();
		   			 	$("#validateCode").attr("src","../login/validateCode/images?"+Math.random())
		   			 	return false;
		   			 }else if(data=="-用户名/密码输入出错！"){
		   			 	alert('用户名或密码错误');
		   			 	$("#valcode").val("");
		   			 	$("#validateCode").attr("src","../login/validateCode/images?"+Math.random());
		   			 	return false;
		   			 }else if(data=="+登录成功！"){
			   			window.parent.location = "../admin/loginSuccess";
						return false;
		   			 }
				  }
				});
	   		return false;
	      }
			return false;
	     });
	   });
});